package com.yugu.park.system.controller;
import java.util.Arrays;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import com.yugu.park.dto.TreeNode;
import com.yugu.park.system.entity.SysMenuEntity;
import com.yugu.park.system.service.SysMenuService;
import com.yugu.util.ResponseUtil;
import com.yugu.util.SearchPage;
import com.github.pagehelper.PageInfo;

/**
 * 菜单权限表
 *
 * @author guxf
 * @email sjzyug@163.com
 * @date 2023-08-17 15:04:07
 */
@Api(tags = {"菜单权限表"})
@RestController
@RequestMapping("system/sysmenu")
public class SysMenuController {
    @Autowired
    private SysMenuService service;

    /**
     * 列表
     */

    @ApiOperation(value="分页查询", notes="分页查询")
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public ResponseUtil.Result<PageInfo<SysMenuEntity>> page (@RequestBody SearchPage<SysMenuEntity> search){
        PageInfo<SysMenuEntity> page = service.page(search);
        return ResponseUtil.addSuccess(page);
    }
    @ApiOperation(value="查看所有", notes="查看所有")
    @GetMapping("/list")
    public ResponseUtil.Result<List<SysMenuEntity>> list(){
		List<SysMenuEntity> sysMenu = service.selectMenuList();
        return ResponseUtil.addSuccess(sysMenu);
    }
	@ApiOperation(value="查看详情", notes="查看详情")
    @GetMapping("/info/{menuId}")
    public ResponseUtil.Result<SysMenuEntity> info(@PathVariable("menuId") String menuId){
		SysMenuEntity sysMenu = service.getById(menuId);
        return ResponseUtil.addSuccess(sysMenu);
    }
    @ApiOperation(value="新增", notes="新增")
    @RequestMapping(value="/save", method= RequestMethod.POST)
    public ResponseUtil.Result<Boolean> save(@RequestBody SysMenuEntity sysMenu){
		service.save(sysMenu);
         return ResponseUtil.addSuccess(true);
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改", notes="修改")
    @RequestMapping(value="/update", method = RequestMethod.PUT)
    public ResponseUtil.Result<Boolean> update(@RequestBody SysMenuEntity sysMenu){
		service.updateById(sysMenu);
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="删除", notes="删除")
    @RequestMapping(value="/delete", method = RequestMethod.DELETE)
    public ResponseUtil.Result<Boolean> delete(@RequestBody String[] menuIds){
		service.removeByIds(Arrays.asList(menuIds));
        return ResponseUtil.addSuccess(true);
    }
    @ApiOperation(value="查询权限树", notes="查询权限树")
    @GetMapping("/getTree")
    public ResponseUtil.Result<List<TreeNode>> tree(){
    	return ResponseUtil.addSuccess(service.selectTreeList());
    }


}
